package io.xdag.block.model;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.apache.commons.lang3.ArrayUtils;

import io.xdag.io.Struct;

public class XdagStorageSum extends Struct implements Serializable {
	private static final long serialVersionUID = 1L;
	public Unsigned64 sum = new Unsigned64();
	public Unsigned64 size = new Unsigned64();
	
	
	private ByteBuffer bb;

	public XdagStorageSum(Byte[] bytes) {
		this.setByteBuffer(bytes);
	}
	
	/**
	 * 初始化对象buffer
	 * @param bytes
	 */
	public void setByteBuffer(Byte[] bytes) {
		byte[] bs = ArrayUtils.toPrimitive(bytes);
		bb = ByteBuffer.wrap(bs);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		this.setByteBuffer(bb, 0);
	}
	
	@Override
	public boolean isPacked() {
		return true;//对齐问题
	}
	
	@Override
	public ByteOrder byteOrder() {
		return ByteOrder.LITTLE_ENDIAN;
	}


	public Unsigned64 getSum() {
		return sum;
	}

	public void setSum(Unsigned64 sum) {
		this.sum = sum;
	}

	public Unsigned64 getSize() {
		return size;
	}

	public void setSize(Unsigned64 size) {
		this.size = size;
	}

	@Override
	public String toString() {
		return "XdagStorageSum [sum=" + sum + ", size=" + size + "]";
	}
}
